package main

import (
	"context"
	consulService "demo/consul"
	"demo/proto/greeter"
	"fmt"
	"google.golang.org/grpc"
	"net"
)

type Hello struct {
}

//	func (h Hello) mustEmbedUnimplementedGreeterServer() {
//		fmt.Println(1)
//	}
func (h Hello) SayHello(c context.Context, req *greeter.HelloReq) (*greeter.HelloRes, error) {
	fmt.Println(req)
	return &greeter.HelloRes{
		Message: "hi" + req.Name,
	}, nil
}

func main() {
	//1.初始化一个grpc对象
	grpcServer := grpc.NewServer()
	//2.注册服务
	greeter.RegisterGreeterServer(grpcServer, new(Hello))
	//3.设置监听
	listener, err := net.Listen("tcp", "127.0.0.1:8800")
	if err != nil {
		fmt.Println(err)
	}
	defer listener.Close()
	//4.去consul注册服务
	consulService.RegisterServiceToConsul("greeter", "greeter-service-1", 8800)
	//5.启动服务
	grpcServer.Serve(listener)
}
